<?php
$connection = Yii::app()->db;

#Get Sponsor List   
$sql = "SELECT member_id, first_name, last_name FROM gn_members";
$command = $connection->createCommand($sql);
$dataReader = $command->query();
$members = array();
foreach( $dataReader as $row ) { 
  $members[$row['member_id']] = '['.$row['member_id'].'] '.$row['last_name']. ', ' . $row['first_name']; 
}


$sql = "SELECT * FROM gn_products";
$command = $connection->createCommand($sql);
$dataReader = $command->query();
$products = array();
foreach( $dataReader as $row ) { 
  $products[$row['product_id']] = $row['product_name'];
}
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'sales-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'member_id'); ?>
        <?php echo $form->dropDownList($model,'member_id', $members ); ?>
        <?php echo $form->error($model,'member_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'product_id'); ?>
        <?php echo $form->dropDownList($model,'product_id', $products ); ?>
        <?php echo $form->error($model,'product_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'quantity'); ?>
		<?php echo $form->textField($model,'quantity'); ?>
		<?php echo $form->error($model,'quantity'); ?>
	</div>

	<div class="row">
		<?php echo CHtml::activeLabelEx($model,'dt_sale'); ?>
            <?php if ( $model->isNewRecord ) { 
			      $date = date("Y-m-d"); ?>
              <?php echo CHtml::activeTextField($model,'dt_sale',array("id"=>"dt_sale", 'value'=>$date)); ?>
            <?php } else { ?>
               <?php echo CHtml::activeTextField($model,'dt_sale',array("id"=>"dt_sale")); ?>
            <?php } ?>
            <!--&nbsp;(calendar appears when textbox is clicked)-->
            <?php $this->widget('application.extensions.calendar.SCalendar',
                array(
                'inputField'=>'dt_sale',
                'ifFormat'=>'%Y-%m-%d',
            ));
            ?>
	</div>


	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->